#ifndef DIRECTIONCONTROLWIDGET_H
#define DIRECTIONCONTROLWIDGET_H

#include <QWidget>
#include <QPoint>

class DirectionControlWidget : public QWidget
{
    Q_OBJECT
public:
    explicit DirectionControlWidget(QWidget *parent = nullptr);
    void startDragging(const QPoint& pos);
    
    double getXSpeed() const { return m_xSpeed; }
    double getYSpeed() const { return m_ySpeed; }

signals:
    void directionChanged(double x, double y);

protected:
    bool event(QEvent *event) override;
    void paintEvent(QPaintEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;

private:
    bool m_isDragging = false;
    QPoint m_currentPos;
    QPoint m_center;
    int m_radius;
    double m_xSpeed = 0.0;
    double m_ySpeed = 0.0;
    
    void calculateDirection(const QPoint& pos);
    QPoint limitToCircle(const QPoint& pos);
    void drawBackground(QPainter& painter, int innerRadius);
    void drawCenterPoint(QPainter& painter, int innerRadius);
    void drawDirectionLine(QPainter& painter);
};

#endif // DIRECTIONCONTROLWIDGET_H
